package frame.factory;

import frame.pojo.Configuration;
import frame.pojo.Mapper;
import frame.utils.XmlConfigBuilder;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import java.io.InputStream;
import java.util.List;

/**
 * FileName: SqlSessionFactoryBuilder
 * Author:   xuan zongjun
 * Date:     2020/11/4 11:49
 * Description:  构建工厂，并在这里读取一次xml，避免xml重复读取
 */


public class SqlSessionFactoryBuilder {

    /**
     * 构建工厂的入口，让用户传入配置文件的文件流
     * @param inputStream
     * @return
     */
    public SqlSessionFactory build(InputStream inputStream){
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactory();
        // 读取数据源信息xml为Configuration对象
        XmlConfigBuilder xmlConfigBuilder = new XmlConfigBuilder();
        Configuration configuration = xmlConfigBuilder.loadXmlConfig(inputStream);
        sqlSessionFactory.setConfiguration(configuration);
        return sqlSessionFactory;
    }






}
